#include('header.html', {title: '后台管理·视频审核', audit: 'active'})

<style>
  .layui-btn + .layui-btn {
    margin-left: 3px;
  }
</style>

<div class="body-wrapper">
  <div class="layui-card">
    <div class="layui-card-header">
      <h3 class="card-title font-yy">
        视频审核
      </h3>
    </div>
    <div class="layui-card-body">
      <table id="taskAudit" lay-filter="taskAudit"></table>
    </div>
  </div>
</div>

<script type="text/html" id="tools">
  <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="preview">
    <i class="layui-icon layui-icon-video"></i>预览
  </a>
  {{# if(d.status === 0) { }}
  <a class="layui-btn layui-btn-xs" lay-event="audit">发布任务</a>
  {{# } else { }}
  <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="audit">隐藏任务</a>
  {{# } }}
</script>

<script>
  layui.use(['table', 'form', 'jquery', 'layer'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;

    table.render({
      elem: '#taskAudit',
      page: true,
      url: '/admin/vedioaudit/page',
      method: 'post',
      cols: [[
        {type: 'numbers', title: '序号'},
        {field: 'name', title: '视频名'},
        {
          title: '所属课程',
          templet: '<i><a title="查看详情" target="_blank" ' +
          'href="/course/{{d.course.id}}/info">{{d.course.name}}</span></i>'
        },
        {
          title: '发布者', templet: function (d) {
            var user = d.course.user;
            var v = user.name;
            if (v == null || v.length <= 0) {
              v = user.username;
            }
            return '<a title="查看用户信息" target="_blank" href="/user/' + user.id + '/home">' +
                '<span class="layui-badge layui-bg-blue">' + v + '</span></a>';
          }
        },
        {
          title: '状态', templet: function (d) {
            var status = d.status;
            if (status === 1) {
              return '<span class="layui-badge layui-bg-green">已发布</span>';
            }
            return '<span class="layui-badge layui-bg-red">未发布</span>';
          }, width: 100
        },
        {field: 'time', title: '发布时间'},
        {title: '操作', toolbar: '#tools'}
      ]],
      parseData: function (res) {
        return {
          "code": 0,
          "msg": res.msg,
          "count": (res.payload ? res.payload.totalRows : 0),
          "data": (res.payload ? res.payload.rows : [])
        };
      }
    });

    var methods = {
      preview: function (task) {
        var cid = task.course.id;
        var mid = task.materialId;
        var tid = task.id;
        layer.open({
          type: 2,
          title: '<span class="layui-badge layui-bg-cyan">'+task.name+'</span> 视频预览',
          area: ['580px', '443.5px'],
          content: '/course/' + cid + '/task/' + tid + '/video?pv=1&wid=' + mid
        })
      },
      audit: function (task) {
        $.post('/admin/vedioaudit/audit', {tid: task.id}, function (data) {
          if (data.success) {
            if (task.status === 0) {
              layer.msg('发布成功', {icon: 6, time: 1200});
            } else {
              layer.msg('取消发布成功', {icon: 5, time: 1200});
            }
            table.reload('taskAudit');
          }
        });
      }
    };

    table.on('tool', function (tool) {
      var m = methods[tool.event];
      if (m != null) {
        m.call(this, tool.data);
      }
    });


  });
</script>

#include('footer.html')
